package com.itedge.infrastructure.service.process;

import java.util.List;

import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.task.Task;

/**
 * Interface for process services.
 * 
 * @author jhe
 *
 */
public interface IProcessService<E> {
	
	/**
	 * Creates process for given entity, links process to entity, and persists entity.
	 * 
	 * @param processEntity
	 * @return process entity with new linked process set
	 */
	public E createEntityProcess(E processEntity);
	
    /**
     * Read all pending task instances for given process instance, sort them according to task names(ascending).
     * 
     * @param procId
     * @return list with all pending tasks for given process instance
     */
	public List<Task> readAllPendingTasksForProcessInstance(String procId);
	
	/**
	 * Read all pending task instances for all process instances of given process service (process key), 
	 * sort them according to task names(ascending).
	 * 
	 * @return list with all pending tasks for given process service (process key)
	 */
	public List<Task> readAllPendingTasks();
	
	/**
	 * Read all pending tasks in specified range.
	 * 
	 * @param firstResult
	 * @param maxResults
	 * @return list with pending tasks in specified range
	 */
	public List<Task> readPendingTasks(int firstResult, int maxResults);
	
	/**
	 * Read pending task which have name like name in argument with max specified number of results.
	 * 
	 * @param likeName
	 * @param maxResults
	 * @return list with pending tasks searched by name, optional limited to maxResults parameter
	 */
	public List<Task> readPendingTasksByName(String likeName, Integer maxResults);
	
	/**
	 * Count all pending tasks.
	 * 
	 * @return count of all pending tasks
	 */
	public long countAllPendingTasks();
	
	/**
	 * Cancel all pending tasks by task trigger.
	 * 
	 * @param procId
	 * @param deletingTaskId
	 */
	public void cancelAllPendingTasksByTaskTrigger(String procId, String deletingTaskId);
	
    /**
     * Get all completed historic instances of tasks.
     * 
     * @param procId
     * @param orderByStart
     * @param asc
     * @return list of all completed historic task instances for given process instance
     */
    public List<HistoricTaskInstance> readAllCompletedTasksForProcess(String procId, boolean orderByStart, boolean asc);
    
    /**
     * Get task by id.
     * 
     * @param id
     * @return task instance with specified id
     */
    public Task getTaskById(String id);
    
    /**
     * Get historic task instance by id.
     * 
     * @param id
     * @return task history instance with specified id
     */
    public HistoricTaskInstance getHistoryTaskById(String id);   
    
    /**
     * Check if process for given task is still active, or finished.
     * 
     * @param taskId
     * @return true if process is still active, false otherwise
     */
    public boolean isProcessForGivenTaskActive(String taskId);
    
    /**
     * Returns process key. 
     * 
     * @return process key for implementing process service
     */
    public String getProcessKey();

}
